package com.lb.videoplay.activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.res.ResourcesCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


import com.blankj.utilcode.util.ToastUtils;
import com.jude.swipbackhelper.SwipeBackHelper;
import com.lb.videoplay.R;
import com.lb.videoplay.statuslib.StatusUtil;
import com.lb.videoplay.utils.CommonUtils;

import java.sql.Time;
import java.util.Timer;
import java.util.TimerTask;


/**
 * Created by:Mr.lb
 * 时间：2018/8/31
 * 包名：com.lb.videoplay.activity
 * 描述：意见反馈
 */
public class FeedbackActivity extends FragmentActivity implements View.OnClickListener {

    private TextView mCenterTitle;
    private TextView mLeftTitleIcon;
    private EditText mEtContact;
    private EditText mEtMode;
    private Button mBtSubmit;
    private Time mTime;

    @Override
    protected void onDestroy() {
        super.onDestroy();
        SwipeBackHelper.onDestroy(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        SwipeBackHelper.onCreate(this);  //右侧滑动退出
        initWidget();
        initTitle();
        initEvent();
        textWacher();
    }

    //监听EditText
    private void textWacher() {
        mEtContact.addTextChangedListener(mTextWatcher);
        mEtMode.addTextChangedListener(mTextWatcher);
    }

    TextWatcher mTextWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (mEtContact.length() > 0 && mEtMode.length() > 0) {
                mBtSubmit.setBackgroundResource(R.drawable.button_login);
                mBtSubmit.setEnabled(true);
            } else {
                mBtSubmit.setBackgroundResource(R.drawable.bt_width_select);
                mBtSubmit.setEnabled(false);
            }
        }
    };



    public void initWidget() {
        mLeftTitleIcon = findViewById(R.id.left_title_icon);
        mCenterTitle = findViewById(R.id.center_title);
        mEtContact = findViewById(R.id.ed_contact);
        mEtMode = findViewById(R.id.ed_mode);
        mBtSubmit = findViewById(R.id.bt_submit);
    }


    public void initEvent() {
        mLeftTitleIcon.setOnClickListener(this);
        mBtSubmit.setOnClickListener(this);
    }

    //初始化标题
    public void initTitle() {
        // 第二个参数是是否沉浸,第三个参数是状态栏字体是否为黑色
        StatusUtil.setSystemStatus(this, true, true);
        mCenterTitle.setText(getText(R.string.app_me_feedback));
        Drawable nav_up = ResourcesCompat.getDrawable(getResources(), R.drawable.back, null);
        nav_up.getMinimumHeight();
        nav_up.setBounds(0, 0, nav_up.getIntrinsicWidth(), nav_up.getIntrinsicWidth());
        mLeftTitleIcon.setCompoundDrawables(null, null, nav_up, null);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        SwipeBackHelper.onPostCreate(this);
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.left_title_icon) {
            finish();
        } else if (i == R.id.bt_submit) {
            CommonUtils commonUtils=new CommonUtils(this);
            commonUtils.showLoadDialog("");
            new Handler().postDelayed(new Runnable(){

                public void run() {
                    ToastUtils.showShort("感谢您的反馈");
                    finish();
                }
            }, 1000);
        }
    }
}
